package com.ebj.dao.h2;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

import com.ebj.conf.ConfigManager;
import com.ebj.conf.ConfigurationSchema;
import com.ebj.dao.DBBaseDaoI;
import com.ebj.h2db.H2DBService;
import com.google.common.base.Stopwatch;
import com.google.common.base.Strings;

public class H2DBDao implements DBBaseDaoI {
    private Logger logger = Logger.getLogger(H2DBDao.class);
    
    private String tableName;
    private Object[] params;
    private Map<String, Double> value_map = null;
    
    private Connection conn =null;
    private Statement stmt = null;
    private ResultSet rst = null;
    
    private ConfigurationSchema config = null;
    private H2DBService h2dbService = null;
    
    private String sql_template_table_drop = "DROP TABLE IF EXISTS %s";
    private String sql_template_table_create = "CREATE TABLE %s(%s)";
    private String sql_template_table_insert_or_update = "INSERT INTO %s %s VALUES %s ON DUPLICATE KEY UPDATE %s.rrate=VALUES(rrate), %s.crate=VALUES(crate);";
    private String sql_template_table_query = "SELECT %S FROM %S";
//    private final String __COLUM_NAMES = "id int(32) unsigned NOT NULL AUTO_INCREMENT,rrate decimal(10,4) NOT NULL,crate decimal(10,4) NOT NULL,lcurrency varchar(3) NOT NULL,rcurrency varchar(3) NOT NULL,isDeleted tinyint(1) DEFAULT '0',last_update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (id),UNIQUE KEY YAHOO_XCHANGE_RATE_lcurrency_IDX (lcurrency,rcurrency),KEY lcurrency (lcurrency) USING HASH,KEY rcurrency (rcurrency) USING HASH";
    /*
     * CREATE TABLE UM_ROLES (
     *      ID INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
     *      RRATE DECIMAL(10,4) NOT NULL,
     *      CRATE DECIMAL(10,4) NOT NULL,
     *      LCURRENCY VARCHAR(3) NOT NULL,
     *      RCURRENCY VARCHAR(3) NOT NULL,
     *      IS_DELETED TINYINT DEFAULT 0,
     *      LAST_UPDATE_TIME TIMESTAMP AS CURRENT_TIMESTAMP(),
     *      PRIMARY KEY (ID),UNIQUE (LCURRENCY, RCURRENCY)
     *  );
     */
    // private final String __COLUM_NAMES = "ID INT PRIMARY KEY AUTO_INCREMENT NOT NULL,RATE_FROM_TO DECIMAL(10,4) NOT NULL,RATE_USD_TO DECIMAL(10,4) NOT NULL,CURRENCY_FROM VARCHAR(3) NOT NULL,CURRENCY_TO VARCHAR(3) NOT NULL,IS_DELETED TINYINT DEFAULT 0,LAST_UPDATE_TIME TIMESTAMP AS CURRENT_TIMESTAMP(),PRIMARY KEY (ID),UNIQUE (CURRENCY_FROM, CURRENCY_TO)";
    private final String __COLUM_NAMES = "ID INT AUTO_INCREMENT NOT NULL,"
            + "RATE_FROM_TO DECIMAL(10,4) NOT NULL,"
            + "RATE_USD_TO DECIMAL(10,4) NOT NULL,"
            + "CURRENCY_FROM VARCHAR(3) NOT NULL,"
            + "CURRENCY_TO VARCHAR(3) NOT NULL,"
            + "IS_DELETED TINYINT DEFAULT 0,"
            + "LAST_UPDATE_TIME TIMESTAMP NOT NULL AS CURRENT_TIMESTAMP(),"
            + "PRIMARY KEY (ID),"
            + "UNIQUE (CURRENCY_FROM, CURRENCY_TO)";
    private static final String __CURRENCY_USD = "USD";
    
    private static H2DBDao h2dbDao = null;
    public static H2DBDao getInstance() {
        if (null == h2dbDao) {
            h2dbDao = new H2DBDao();
        }
        return h2dbDao;
    }
    
    private H2DBDao() {
        config = ConfigManager.getInstance().getConfig();
        h2dbService = H2DBService.getInstance();
        
        this.conn = h2dbService.getH2Conn();
        if (null != this.conn) {
            try {
                stmt = this.conn.createStatement();
            } catch (SQLException e) {
                logger.error("Create SQL Statement Error", e);
            }
        }
        
//        sql_template_table_drop = config.getSQLTmplTableDrop(this.tableName); // property-binder framework bug: string 'DROP TABLE IF EXISTS %s' converts to 'DROP TABLE IF EXISTS null'
//        sql_template_table_create =config.getSQLTmplTableCreate(this.tableName, __COLUM_NAMES);
//        sql_template_table_insert_or_update = config.getSQLTmplInsertOrUpdate();
//        sql_template_table_query = config.getSQLTmplQuery(colums, tableName);
    }

    public boolean createTable() {
        boolean result = false;
        
        boolean step_a = sqlExecutor(config.getSQLTmplTableDrop(this.tableName));
        boolean step_b = sqlExecutor(config.getSQLTmplTableCreate(this.tableName, __COLUM_NAMES));
        if (step_a && step_b) {
        	result = true;
        }else {
        	logger.error("Create Table Error.");
        }
        
        return result;
    }
    
    public boolean createTable(String tableName) {
    	boolean result = false;
    	if (!Strings.isNullOrEmpty(tableName)) {
    		String str_a = String.format(sql_template_table_drop, tableName);
    		String str_b = String.format(sql_template_table_create, tableName, __COLUM_NAMES);
    		boolean step_a = sqlExecutor(str_a);
    		boolean step_b = sqlExecutor(str_b);
    		if (step_a && step_b) {
    			result = true;
    		}else {
    			logger.error("Create Table Error.");
    		}
    	}
    	return result;
    }
    
    // insert data
//            stat.execute("INSERT INTO TEST VALUES('Hello World')");
//
//            ResultSet result = stat.executeQuery("select name from test ");
//            int i = 1;
//            while (result.next()) {
//                System.out.println(i++ + ":" + result.getString("name"));
//            }
//            result.close();
//            stat.close();
//            conn.close();
    private boolean sqlExecutor(String sql) {
        boolean result = false;
        if (null != this.stmt && !Strings.isNullOrEmpty(sql)) {
            try {
                stmt.execute(sql);
                result = true;
            } catch (SQLException e) {
                logger.error("Execute SQL Error", e);
            }
        }
        return result;
    }
    
    private ResultSet queryExecutor(String sql) {
        if (null != this.conn && !Strings.isNullOrEmpty(sql)) {
            PreparedStatement psmt = null;
            try {
                psmt = this.conn.prepareStatement(sql);
                rst = psmt.executeQuery();
            } catch (SQLException e) {
                logger.error("SQL Query Error", e);
            }
        }
        
        return rst;
    }
    private void closeConn(Connection conn, Statement stmt, ResultSet rst) {
        if (rst != null) {
            try {
                rst.close();
                logger.info("SQL ResultSet Closed.");
            } catch (SQLException e) {
                logger.error("", e);
            }
        }

        if (stmt != null) {
            try {
                stmt.close();
                logger.info("SQL Statement Closed.");
            } catch (SQLException e) {
                logger.error("", e);
            }
        }

        if (conn != null) {
            try {
                conn.close();
                logger.info("H2DB-Conn Closed.");
            } catch (SQLException e) {
                logger.error("", e);
            }
        }
    }
    
    private String getSQLValues() {
        StringBuilder sql_kit_values = new StringBuilder();
        if (null != this.value_map && this.value_map.size() > 0) {
            for (Entry<String, Double> entry : this.value_map.entrySet()) {
                String key = entry.getKey();
                String currency_from = key.substring(0, 3);
                String currency_to = key.substring(3, key.length());
                
                // Double rrate = entry.getValue();
                Double rate_from_to = entry.getValue();
                Double rate_usd_to = this.value_map.get(__CURRENCY_USD + currency_to);
                if (null == rate_usd_to) {
                    rate_usd_to = 1.0;
                }
                /*
                 * (CURRENCY_FROM, CURRENCY_TO, RATE_FROM_TO, RATE_USD_TO)
                 * "('DDY','DIY','0.3399','1.12389'),"
                 */
                String values_meta = "('" + currency_from + "','" + currency_to + "','" + rate_from_to + "','" + rate_usd_to + "'),";
                sql_kit_values.append(values_meta);
            }
        }
        return sql_kit_values.toString();
    }
    
    private String buildInsertSQLHeader() {
        StringBuilder sql_builder = new StringBuilder();
        sql_builder.append(String.format("INSERT INTO %s", this.tableName));
        sql_builder.append("(CURRENCY_FROM, CURRENCY_TO, RATE_FROM_TO, RATE_USD_TO) ");
        sql_builder.append("VALUES");
        return sql_builder.toString();
    }
    
    public boolean doInsertOrUpdate() {
        boolean result = false;
        // String sql = "INSERT INTO YAHOO_XCHANGE_RATE (RRATE, CRATE, LCURRENCY, RCURRENCY) VALUES ('0.3399', '1.12389', 'DDY','DIY'),('0.5566', '2.12389', 'DDK','DJY') ON DUPLICATE KEY UPDATE YAHOO_XCHANGE_RATE.RRATE=VALUES(RRATE), YAHOO_XCHANGE_RATE.CRATE=VALUES(CRATE)";
        String sql_insert_values = "INSERT INTO YAHOO_XCHANGE_RATE "
                + "(CURRENCY_FROM, CURRENCY_TO, RATE_FROM_TO, RATE_USD_TO) "
                + "VALUES "
//                + "('DDY','DIY','0.3399','1.12389'),"
//                + "('MYR','USD','0.3112','1.0'),"
//                + "('DDK','DJY','0.5566','2.12389') ";
                + "('MYR','USD','0.3112','1.0'),('THB','GBP','0.0181','0.5871'),('HKD','JPY','13.1399','101.845'),('SGD','HKD','6.2103','7.7508'),('CNY','CHF','0.1434','0.8933'),('JPY','NOK','0.06','6.1107'),('SEK','GBP','0.088','0.5871'),('SEK','INR','8.9991','60.035'),('TRY','MYR','1.5095','3.213'),('GBP','INR','102.2513','60.035'),('NZD','BRL','1.9388','2.223'),('CNY','NOK','0.9808','6.1107'),('CAD','CHF','0.8252','0.8933'),('GBP','RON','5.4937','3.2253'),('LVL','NOK','11.9944','6.1107'),('LTL','CNY','2.4578','6.231'),('GBP','NOK','10.4071','6.1107'),('USD','SEK','6.6709','6.6709'),('ILS','SGD','0.3626','1.2481'),('RUB','JPY','2.9719','101.845'),('PHP','INR','1.3694','60.035'),('ILS','CZK','5.8513','20.142'),('RON','JPY','31.5725','101.845'),('LVL','RON','6.3312','3.2253'),('ZAR','RUB','3.2195','34.272'),('LTL','MYR','1.2674','3.213'),('MYR','RUB','10.6657','34.272'),('CZK','CHF','0.0444','0.8933'),('HKD','CNY','0.8039','6.231'),('TRY','MXN','6.0996','12.982'),('AUD','SEK','6.2778','6.6709'),('PHP','CNY','0.1421','6.231'),('AUD','CHF','0.8406','0.8933'),('BGN','USD','0.6936','1.0'),('MYR','LTL','0.789','2.5352'),('HRK','LTL','0.4557','2.5352'),('CZK','ZAR','0.5285','10.6466'),('NOK','GBP','0.0961','0.5871'),('HUF','CZK','0.0899','20.142'),('NOK','THB','5.3139','32.47'),('RON','TRY','0.6598','2.1285'),('LVL','PLN','5.9541','3.0338'),('IDR','SGD','1.0E-4','1.2481'),('EUR','PLN','4.1321','3.0338'),('SEK','ILS','0.516','3.4423'),('INR','MXN','0.2162','12.982'),('MXN','LVL','0.0392','0.5095'),('RON','DKK','1.6971','5.4744'),('HKD','DKK','0.7063','5.4744'),('IDR','KRW','0.0851','1018.755'),('LTL','USD','0.3945','1.0'),('BGN','EUR','0.5092','0.7342'),('GBP','ILS','5.8629','3.4423'),('GBP','PHP','74.6681','43.84'),('KRW','CZK','0.0198','20.142'),('SEK','RON','0.4835','3.2253'),('PHP','ILS','0.0785','3.4423'),('CNY','USD','0.1605','1.0'),('RUB','CZK','0.5878','20.142'),('CAD','NZD','1.0592','1.1466'),('RON','HKD','2.4028','7.7508'),('RON','BRL','0.6891','2.223'),('KRW','NZD','0.0011','1.1466'),('ILS','SEK','1.9378','6.6709'),('LTL','MXN','5.1209','12.982'),('BRL','USD','0.4498','1.0'),('LVL','ILS','6.7562','3.4423'),('CNY','JPY','16.3449','101.845'),('IDR','SEK','6.0E-4','6.6709'),('EUR','RUB','46.6773','34.272'),('AUD','SGD','1.1746','1.2481'),('HRK','LVL','0.0916','0.5095'),('USD','SGD','1.2481','1.2481'),('JPY','GBP','0.0058','0.5871'),('TRY','KRW','478.6258','1018.755'),('INR','MYR','0.0535','3.213'),('EUR','HKD','10.5571','7.7508'),('RUB','HKD','0.2262','7.7508'),('HRK','USD','0.1798','1.0'),('IDR','ILS','3.0E-4','3.4423'),('SEK','KRW','152.7083','1018.755'),('CHF','GBP','0.6573','0.5871'),('HRK','SEK','1.1991','6.6709'),('CHF','CAD','1.2119','1.0826'),('ILS','ZAR','3.0925','10.6466'),('SGD','USD','0.8012','1.0'),('SEK','MYR','0.4816','3.213'),('MYR','BRL','0.6919','2.223'),('BGN','DKK','3.7969','5.4744'),('DKK','NZD','0.2095','1.1466'),('BRL','SEK','3.0007','6.6709'),('HKD','USD','0.129','1.0'),('SGD','NOK','4.8959','6.1107'),('RUB','LTL','0.074','2.5352'),('LVL','INR','117.8312','60.035'),('HUF','ILS','0.0154','3.4423'),('ILS','CNY','1.8101','6.231'),('ZAR','CAD','0.1017','1.0826'),('JPY','CHF','0.0088','0.8933'),('MXN','CZK','1.5515','20.142'),('AUD','NOK','5.7505','6.1107'),('NZD','RUB','29.8874','34.272'),('PHP','KRW','23.238','1018.755'),('CNY','HKD','1.2439','7.7508'),('IDR','CNY','5.0E-4','6.231'),('LTL','IDR','4721.6138','11970.0'),('LVL','CHF','1.7533','0.8933'),('ZAR','LVL','0.0479','0.5095'),('CAD','SGD','1.1529','1.2481'),('NZD','KRW','888.4969','1018.755'),('LVL','PHP','86.0451','43.84'),('THB','CAD','0.0333','1.0826'),('LTL','KRW','401.852','1018.755'),('IDR','INR','0.005','60.035'),('MXN','HKD','0.597','7.7508'),('SGD','JPY','81.6023','101.845'),('ZAR','GBP','0.0552','0.5871'),('BRL','SGD','0.5614','1.2481'),('AUD','CAD','1.0188','1.0826'),('SEK','TRY','0.3191','2.1285'),('HRK','SGD','0.2244','1.2481'),('EUR','LVL','0.694','0.5095'),('NZD','TRY','1.8563','2.1285'),('CHF','IDR','13400.7285','11970.0'),('USD','NZD','1.1466','1.1466'),('PLN','AUD','0.3503','1.0626'),('BRL','AUD','0.478','1.0626'),('THB','IDR','368.648','11970.0'),('GBP','SGD','2.1257','1.2481'),('MXN','ZAR','0.82','10.6466'),('HRK','NZD','0.2061','1.1466'),('BRL','EUR','0.3303','0.7342'),('EUR','PHP','59.7129','43.84'),('HRK','CNY','1.1201','6.231'),('LTL','EUR','0.2896','0.7342'),('GBP','SEK','11.3614','6.6709'),('CAD','CNY','5.7559','6.231'),('KRW','LVL','5.0E-4','0.5095'),('RUB','LVL','0.0149','0.5095'),('DKK','RUB','6.2601','34.272'),('LTL','GBP','0.2316','0.5871'),('KRW','HUF','0.2201','224.135'),('PHP','CHF','0.0204','0.8933'),('GBP','CHF','1.5214','0.8933'),('HRK','EUR','0.132','0.7342'),('GBP','PLN','5.1664','3.0338'),('HUF','INR','0.2678','60.035'),('MYR','EUR','0.2285','0.7342'),('RON','NOK','1.8945','6.1107'),('SEK','MXN','1.946','12.982'),('USD','CAD','1.0826','1.0826'),('TRY','AUD','0.4992','1.0626'),('IDR','USD','1.0E-4','1.0'),('CZK','NOK','0.3034','6.1107'),('TRY','EUR','0.3449','0.7342'),('PLN','CAD','0.3568','1.0826'),('SGD','CHF','0.7157','0.8933'),('EUR','LTL','3.453','2.5352'),('CZK','SEK','0.3312','6.6709'),('CAD','SEK','6.1624','6.6709'),('LTL','CHF','0.3523','0.8933'),('MXN','CNY','0.48','6.231'),('SGD','NZD','0.9187','1.1466'),('RUB','CNY','0.1818','6.231'),('ILS','LVL','0.148','0.5095'),('PHP','EUR','0.0167','0.7342'),('RON','HRK','1.7247','5.5628'),('PHP','USD','0.0228','1.0'),('ZAR','NZD','0.1077','1.1466'),('SEK','RUB','5.1368','34.272'),('ILS','CAD','0.3145','1.0826'),('JPY','SGD','0.0123','1.2481'),('CZK','CAD','0.0537','1.0826'),('ZAR','BRL','0.2088','2.223'),('PLN','CHF','0.2945','0.8933'),('HUF','MXN','0.0579','12.982'),('CHF','INR','67.2108','60.035'),('INR','BGN','0.024','1.4417'),('JPY','SEK','0.0655','6.6709'),('EUR','HUF','305.2932','224.135'),('CHF','MYR','3.597','3.213'),('DKK','LVL','0.0931','0.5095'),('CAD','GBP','0.5424','0.5871'),('RON','PHP','13.5906','43.84'),('DKK','TRY','0.3888','2.1285'),('MXN','JPY','7.8449','101.845'),('THB','CHF','0.0275','0.8933'),('NZD','ILS','3.0022','3.4423'),('NZD','PHP','38.2346','43.84'),('HUF','MYR','0.0143','3.213'),('CHF','PLN','3.3959','3.0338'),('EUR','TRY','2.8992','2.1285'),('USD','CHF','0.8933','0.8933'),('HRK','HKD','1.3933','7.7508'),('CZK','SGD','0.062','1.2481'),('MXN','EUR','0.0566','0.7342'),('EUR','BRL','3.0279','2.223'),('BRL','CZK','9.0612','20.142'),('KRW','HRK','0.0055','5.5628'),('SGD','LTL','2.0313','2.5352'),('DKK','RON','0.5892','3.2253'),('ILS','LTL','0.7365','2.5352'),('EUR','HRK','7.5769','5.5628'),('LVL','RUB','67.265','34.272'),('RUB','HRK','0.1623','5.5628'),('HKD','HRK','0.7177','5.5628'),('NOK','BGN','0.2359','1.4417'),('HUF','KRW','4.5452','1018.755'),('THB','NZD','0.0353','1.1466'),('DKK','LTL','0.4631','2.5352'),('HKD','ZAR','1.3735','10.6466'),('HKD','CZK','2.5986','20.142'),('MYR','CAD','0.3369','1.0826'),('KRW','JPY','0.1','101.845'),('MXN','AUD','0.0818','1.0626'),('PLN','INR','19.7894','60.035'),('CNY','EUR','0.1178','0.7342'),('TRY','CZK','9.4637','20.142'),('INR','ZAR','0.1773','10.6466'),('NZD','RON','2.8133','3.2253'),('PHP','IDR','273.0383','11970.0'),('IDR','CHF','1.0E-4','0.8933'),('CNY','NZD','0.184','1.1466'),('RUB','USD','0.0292','1.0'),('LTL','INR','23.681','60.035'),('NZD','INR','52.3589','60.035'),('HKD','HUF','28.9182','224.135'),('SGD','EUR','0.5883','0.7342'),('SGD','LVL','0.4082','0.5095'),('HRK','CHF','0.1606','0.8933'),('ILS','NZD','0.3331','1.1466'),('JPY','CAD','0.0106','1.0826'),('EUR','JPY','138.7195','101.845'),('NZD','PLN','2.6455','3.0338'),('INR','DKK','0.0912','5.4744'),('RON','RUB','10.6244','34.272'),('CHF','RON','3.6111','3.2253'),('DKK','GBP','0.1073','0.5871'),('TRY','ILS','1.6172','3.4423'),('LVL','TRY','4.1776','2.1285'),('INR','EUR','0.0122','0.7342'),('NOK','MXN','2.1246','12.982'),('INR','THB','0.5409','32.47'),('MXN','HUF','17.2647','224.135'),('CNY','SEK','1.0706','6.6709'),('HRK','NOK','1.0985','6.1107'),('USD','IDR','11970.0','11970.0'),('PLN','SEK','2.1989','6.6709'),('NZD','MXN','11.3219','12.982'),('ILS','EUR','0.2133','0.7342'),('HRK','JPY','18.3082','101.845'),('RON','HUF','69.4831','224.135'),('RON','PLN','0.9404','3.0338'),('THB','SEK','0.2054','6.6709'),('MYR','NOK','1.9018','6.1107'),('PHP','SGD','0.0285','1.2481'),('NOK','MYR','0.5258','3.213'),('PLN','ILS','1.1347','3.4423'),('MXN','LTL','0.1953','2.5352'),('CNY','LTL','0.4069','2.5352'),('NOK','IDR','1958.9712','11970.0'),('MXN','USD','0.077','1.0'),('CHF','PHP','49.08','43.84'),('LTL','ILS','1.3578','3.4423'),('PHP','MYR','0.0733','3.213'),('NZD','MYR','2.8022','3.213'),('DKK','JPY','18.6045','101.845'),('SGD','CNY','4.9925','6.231'),('GBP','CAD','1.8438','1.0826'),('KRW','AUD','0.001','1.0626'),('JPY','ZAR','0.1045','10.6466'),('AUD','EUR','0.6909','0.7342'),('TRY','INR','28.2053','60.035'),('HUF','EUR','0.0033','0.7342'),('CHF','ILS','3.8537','3.4423'),('USD','GBP','0.5871','0.5871'),('DKK','IDR','2186.6208','11970.0'),('BRL','IDR','5384.6152','11970.0'),('GBP','RUB','58.3668','34.272'),('DKK','BRL','0.4061','2.223'),('AUD','NZD','1.0791','1.1466'),('CNY','SGD','0.2003','1.2481'),('PHP','MXN','0.2961','12.982'),('LTL','SGD','0.4923','1.2481'),('HUF','AUD','0.0047','1.0626'),('EUR','RON','4.3931','3.2253'),('PLN','SGD','0.4114','1.2481'),('CAD','IDR','11057.2256','11970.0'),('SEK','BRL','0.3332','2.223'),('EUR','NOK','8.3227','6.1107'),('NZD','GBP','0.5121','0.5871'),('THB','SGD','0.0384','1.2481'),('ILS','CHF','0.2595','0.8933'),('HKD','AUD','0.1371','1.0626'),('IDR','EUR','1.0E-4','0.7342'),('RUB','AUD','0.031','1.0626'),('LVL','CAD','2.1248','1.0826'),('CNY','LVL','0.0818','0.5095'),('RUB','EUR','0.0214','0.7342'),('MXN','HRK','0.4285','5.5628'),('JPY','BRL','0.0218','2.223'),('ILS','HKD','2.2516','7.7508'),('IDR','MXN','0.0011','12.982'),('RUB','SEK','0.1946','6.6709'),('THB','HRK','0.1713','5.5628'),('CZK','INR','2.9806','60.035'),('SGD','CAD','0.8674','1.0826'),('TRY','SEK','3.1339','6.6709'),('THB','JPY','3.1366','101.845'),('JPY','LVL','0.005','0.5095'),('KRW','HKD','0.0076','7.7508'),('HKD','GBP','0.0758','0.5871'),('MXN','SGD','0.0961','1.2481'),('CHF','RUB','38.365','34.272'),('HRK','AUD','0.191','1.0626'),('PLN','JPY','33.5712','101.845'),('HKD','SEK','0.8606','6.6709'),('SEK','NOK','0.9159','6.1107'),('AUD','TRY','2.0032','2.1285'),('CAD','PLN','2.8023','3.0338'),('IDR','MYR','3.0E-4','3.213'),('ILS','RUB','9.9553','34.272'),('CHF','LTL','2.8382','2.5352'),('SGD','SEK','5.3448','6.6709'),('ZAR','SEK','0.6267','6.6709'),('BGN','AUD','0.737','1.0626'),('THB','CNY','0.1919','6.231'),('MYR','CHF','0.278','0.8933'),('ILS','PLN','0.8812','3.0338'),('LTL','SEK','2.6312','6.6709'),('KRW','TRY','0.0021','2.1285'),('BRL','JPY','45.8142','101.845'),('RON','GBP','0.182','0.5871'),('EUR','USD','1.3621','1.0'),('MYR','SEK','2.0763','6.6709'),('ILS','DKK','1.5902','5.4744'),('CHF','HUF','250.9026','224.135'),('AUD','LVL','0.4795','0.5095'),('DKK','THB','5.9315','32.47'),('TRY','CAD','0.5086','1.0826'),('KRW','DKK','0.0054','5.4744'),('PLN','EUR','0.242','0.7342'),('INR','KRW','16.9694','1018.755'),('JPY','LTL','0.0249','2.5352'),('PLN','USD','0.3296','1.0'),('NOK','JPY','16.6676','101.845'),('HUF','CHF','0.004','0.8933'),('ZAR','CNY','0.5853','6.231'),('NOK','PHP','7.1747','43.84'),('THB','AUD','0.0327','1.0626'),('HUF','ZAR','0.0475','10.6466'),('TRY','SGD','0.5864','1.2481'),('INR','TRY','0.0355','2.1285'),('IDR','CAD','1.0E-4','1.0826'),('BRL','CAD','0.487','1.0826'),('JPY','RON','0.0317','3.2253'),('CHF','LVL','0.5704','0.5095'),('LTL','CAD','0.427','1.0826'),('PHP','THB','0.7406','32.47'),('THB','USD','0.0308','1.0'),('HUF','USD','0.0045','1.0'),('RUB','CHF','0.0261','0.8933'),('SGD','GBP','0.4704','0.5871'),('IDR','RUB','0.0029','34.272'),('EUR','SEK','9.0855','6.6709'),('PLN','CNY','2.0539','6.231'),('AUD','LTL','2.3859','2.5352'),('THB','EUR','0.0226','0.7342'),('AUD','RUB','32.2509','34.272'),('USD','CNY','6.231','6.231'),('HKD','CAD','0.1397','1.0826'),('PHP','ZAR','0.2428','10.6466'),('KRW','RON','0.0032','3.2253'),('NZD','BGN','1.2574','1.4417'),('HUF','CNY','0.0278','6.231'),('CAD','INR','55.457','60.035'),('PLN','LVL','0.1679','0.5095'),('AUD','BRL','2.0921','2.223'),('BGN','CZK','13.971','20.142'),('JPY','NZD','0.0113','1.1466'),('GBP','MYR','5.4724','3.213'),('JPY','HKD','0.0761','7.7508'),('LTL','NOK','2.4104','6.1107'),('SEK','DKK','0.8206','5.4744'),('INR','RON','0.0537','3.2253'),('HUF','NOK','0.0273','6.1107'),('AUD','JPY','95.8473','101.845'),('CHF','TRY','2.3829','2.1285'),('AUD','RON','3.0358','3.2253'),('INR','ILS','0.0573','3.4423'),('NOK','HKD','1.2685','7.7508'),('NOK','DKK','0.8959','5.4744'),('EUR','CAD','1.4745','1.0826'),('JPY','PHP','0.4305','43.84'),('EUR','ZAR','14.4997','10.6466'),('USD','HKD','7.7508','7.7508'),('EUR','SGD','1.6999','1.2481'),('RUB','HUF','6.5399','224.135'),('KRW','NOK','0.006','6.1107'),('GBP','MXN','22.1105','12.982'),('THB','LVL','0.0157','0.5095'),('CNY','MYR','0.5156','3.213'),('DKK','BGN','0.2634','1.4417'),('PHP','CZK','0.4594','20.142'),('THB','HUF','6.9018','224.135'),('PLN','LTL','0.8357','2.5352'),('MXN','CHF','0.0688','0.8933'),('CZK','ILS','0.1709','3.4423'),('ILS','NOK','1.7752','6.1107'),('HUF','SGD','0.0056','1.2481'),('RUB','SGD','0.0364','1.2481'),('MXN','SEK','0.5139','6.6709'),('ILS','RON','0.937','3.2253'),('CHF','NZD','1.2837','1.1466'),('ILS','JPY','29.5863','101.845'),('CAD','ILS','3.1798','3.4423'),('INR','NOK','0.1018','6.1107'),('NOK','PLN','0.4964','3.0338'),('LVL','CZK','39.5299','20.142'),('AUD','PHP','41.2583','43.84'),('RON','THB','10.0659','32.47'),('BRL','HKD','3.4866','7.7508'),('NOK','RUB','5.6084','34.272'),('ILS','HRK','1.6161','5.5628'),('MYR','IDR','3725.4902','11970.0'),('CHF','HRK','6.2281','5.5628'),('MYR','SGD','0.3884','1.2481'),('LVL','THB','63.7291','32.47'),('DKK','HKD','1.4159','7.7508'),('BGN','HKD','5.3762','7.7508'),('CNY','CZK','3.2323','20.142'),('ZAR','SGD','0.1172','1.2481'),('THB','LTL','0.0781','2.5352'),('CHF','BRL','2.4887','2.223'),('GBP','CZK','34.3058','20.142'),('HUF','SEK','0.0298','6.6709'),('SEK','PHP','6.5715','43.84'),('MYR','GBP','0.1827','0.5871'),('JPY','PLN','0.0298','3.0338'),('GBP','CNY','10.6126','6.231'),('NZD','NOK','5.3291','6.1107'),('INR','PLN','0.0505','3.0338'),('CAD','RUB','31.6581','34.272'),('CAD','MYR','2.968','3.213'),('NZD','THB','28.3184','32.47'),('KRW','LTL','0.0025','2.5352'),('SGD','HRK','4.4571','5.5628'),('EUR','NZD','1.5618','1.1466'),('PLN','NZD','0.378','1.1466'),('BGN','LVL','0.3534','0.5095'),('KRW','ZAR','0.0105','10.6466'),('GBP','ZAR','18.1311','10.6466'),('MXN','GBP','0.0452','0.5871'),('RON','MXN','4.0246','12.982'),('USD','LVL','0.5095','0.5095'),('CHF','DKK','6.1283','5.4744'),('NZD','DKK','4.7743','5.4744'),('JPY','RUB','0.3365','34.272'),('ZAR','EUR','0.069','0.7342'),('BRL','NZD','0.5158','1.1466'),('MYR','KRW','317.0728','1018.755'),('HRK','MYR','0.5776','3.213'),('INR','RUB','0.5708','34.272'),('BGN','HUF','155.4692','224.135'),('CAD','KRW','941.0696','1018.755'),('DKK','HUF','40.9402','224.135'),('SEK','BGN','0.2161','1.4417'),('ILS','BRL','0.6458','2.223'),('CZK','MYR','0.1595','3.213'),('RON','IDR','3710.7649','11970.0'),('LVL','EUR','1.4411','0.7342'),('PHP','HRK','0.1269','5.5628'),('RON','MYR','0.996','3.213'),('ILS','HUF','65.1062','224.135'),('RUB','CAD','0.0316','1.0826'),('ZAR','LTL','0.2382','2.5352'),('NOK','RON','0.5279','3.2253'),('HKD','CHF','0.1152','0.8933'),('AUD','PLN','2.8547','3.0338'),('HKD','NZD','0.1479','1.1466'),('CZK','CNY','0.3094','6.231'),('LVL','KRW','1999.519','1018.755'),('IDR','PLN','3.0E-4','3.0338'),('CAD','MXN','11.9923','12.982'),('BRL','LVL','0.2292','0.5095'),('AUD','ZAR','10.0188','10.6466'),('BRL','CHF','0.4018','0.8933'),('MYR','NZD','0.3569','1.1466'),('CAD','TRY','1.9662','2.1285'),('LTL','NZD','0.4523','1.1466'),('HRK','CZK','3.6207','20.142'),('SEK','THB','4.8672','32.47'),('USD','LTL','2.5352','2.5352'),('SGD','HUF','179.59','224.135'),('HUF','CAD','0.0048','1.0826'),('CNY','AUD','0.1705','1.0626'),('HKD','IDR','1544.3538','11970.0'),('RUB','NZD','0.0335','1.1466'),('PHP','AUD','0.0242','1.0626'),('GBP','EUR','1.2505','0.7342'),('GBP','USD','1.7032','1.0'),('RUB','IDR','349.2953','11970.0'),('AUD','HKD','7.2944','7.7508'),('USD','HUF','224.135','224.135'),('CZK','MXN','0.6445','12.982'),('TRY','CHF','0.4197','0.8933'),('INR','BRL','0.037','2.223'),('BGN','JPY','70.6423','101.845'),('BGN','THB','22.522','32.47'),('BRL','CNY','2.803','6.231'),('ZAR','USD','0.0939','1.0'),('CHF','NOK','6.8407','6.1107'),('ZAR','NOK','0.5741','6.1107'),('LVL','MXN','25.4804','12.982'),('BGN','ZAR','7.3839','10.6466'),('INR','PHP','0.7302','43.84'),('SEK','PLN','0.4547','3.0338'),('CAD','NOK','5.6449','6.1107'),('MXN','CAD','0.0834','1.0826'),('KRW','THB','0.0319','32.47'),('AUD','HRK','5.2356','5.5628'),('BRL','LTL','1.1404','2.5352'),('USD','HRK','5.5628','5.5628'),('BGN','HRK','3.8585','5.5628'),('TRY','NOK','2.8707','6.1107'),('TRY','CNY','2.9274','6.231'),('MYR','INR','18.685','60.035'),('MXN','NZD','0.0883','1.1466'),('NOK','TRY','0.3483','2.1285'),('RON','BGN','0.4469','1.4417'),('LVL','MYR','6.3062','3.213'),('HKD','LVL','0.0657','0.5095'),('CAD','BRL','2.0535','2.223'),('CNY','ZAR','1.7085','10.6466'),('NOK','HRK','0.9105','5.5628'),('CZK','AUD','0.0528','1.0626'),('ZAR','CHF','0.0839','0.8933'),('BRL','HUF','100.8165','224.135'),('CAD','RON','2.9798','3.2253'),('CZK','EUR','0.0365','0.7342'),('CZK','USD','0.0496','1.0'),('CZK','KRW','50.5786','1018.755'),('HRK','ZAR','1.9138','10.6466'),('USD','AUD','1.0626','1.0626'),('LVL','CNY','12.2296','6.231'),('CHF','BGN','1.614','1.4417'),('JPY','HRK','0.0546','5.5628'),('USD','CZK','20.142','20.142'),('USD','JPY','101.845','101.845'),('TRY','USD','0.4698','1.0'),('AUD','USD','0.9411','1.0'),('MYR','LVL','0.1586','0.5095'),('PLN','ZAR','3.5094','10.6466'),('LTL','RUB','13.5175','34.272'),('JPY','TRY','0.0209','2.1285'),('THB','CZK','0.6204','20.142'),('NOK','HUF','36.6779','224.135'),('NOK','BRL','0.3638','2.223'),('NZD','ZAR','9.2846','10.6466'),('IDR','BRL','2.0E-4','2.223'),('MYR','CNY','1.9393','6.231'),('DKK','HRK','1.0162','5.5628'),('CHF','THB','36.351','32.47'),('LTL','ZAR','4.1993','10.6466'),('MYR','ILS','1.0714','3.4423'),('IDR','PHP','0.0037','43.84'),('PHP','HUF','5.1127','224.135'),('ZAR','JPY','9.5674','101.845'),('TRY','ZAR','5.0014','10.6466'),('EUR','CHF','1.2167','0.8933'),('AUD','BGN','1.3568','1.4417'),('GBP','KRW','1735.1383','1018.755'),('HKD','LTL','0.3271','2.5352'),('BGN','LTL','1.7584','2.5352'),('BRL','HRK','2.5024','5.5628'),('HKD','SGD','0.161','1.2481'),('BGN','CNY','4.322','6.231'),('THB','HKD','0.2387','7.7508'),('KRW','BGN','0.0014','1.4417'),('MXN','IDR','922.0281','11970.0'),('PLN','CZK','6.6394','20.142'),('TRY','NZD','0.5387','1.1466'),('HKD','ILS','0.4441','3.4423'),('RON','INR','18.6112','60.035'),('INR','NZD','0.0191','1.1466'),('RUB','ILS','0.1004','3.4423'),('PHP','PLN','0.0692','3.0338'),('CAD','BGN','1.3318','1.4417'),('HRK','TRY','0.3826','2.1285'),('NOK','CAD','0.1772','1.0826'),('GBP','DKK','9.3236','5.4744'),('DKK','EUR','0.1341','0.7342'),('SEK','NZD','0.1719','1.1466'),('HUF','BRL','0.0099','2.223'),('BRL','NOK','2.7489','6.1107'),('NOK','LTL','0.4149','2.5352'),('IDR','JPY','0.0085','101.845'),('SEK','ZAR','1.5958','10.6466'),('MXN','PLN','0.2337','3.0338'),('BGN','CHF','0.6196','0.8933'),('GBP','HKD','13.2011','7.7508'),('LTL','LVL','0.201','0.5095'),('CAD','EUR','0.6782','0.7342'),('NOK','SEK','1.0917','6.6709'),('JPY','HUF','2.2006','224.135'),('MXN','BRL','0.1712','2.223'),('SGD','INR','48.1025','60.035'),('IDR','THB','0.0027','32.47'),('DKK','AUD','0.1941','1.0626'),('HRK','MXN','2.3338','12.982'),('ILS','THB','9.4326','32.47'),('LVL','HKD','15.2126','7.7508'),('ZAR','PLN','0.2849','3.0338'),('LVL','DKK','10.7447','5.4744'),('TRY','JPY','47.8483','101.845'),('BGN','TRY','1.4764','2.1285'),('CNY','DKK','0.8786','5.4744'),('CNY','INR','9.6349','60.035'),('IDR','NOK','5.0E-4','6.1107'),('CZK','DKK','0.2718','5.4744'),('MXN','MYR','0.2475','3.213'),('RUB','RON','0.0941','3.2253'),('RON','ILS','1.0671','3.4423'),('PLN','HUF','73.8834','224.135'),('HUF','HKD','0.0346','7.7508'),('ILS','BGN','0.4188','1.4417'),('USD','EUR','0.7342','0.7342'),('NZD','USD','0.8721','1.0'),('DKK','CZK','3.6794','20.142'),('SGD','ILS','2.7581','3.4423'),('SGD','RON','2.5844','3.2253'),('INR','IDR','199.3837','11970.0'),('HKD','RON','0.4161','3.2253'),('HKD','KRW','131.4384','1018.755'),('PHP','HKD','0.1768','7.7508'),('RUB','GBP','0.0171','0.5871'),('SEK','HKD','1.1618','7.7508'),('CNY','TRY','0.3416','2.1285'),('HUF','RON','0.0144','3.2253'),('MYR','AUD','0.3307','1.0626'),('EUR','CNY','8.487','6.231'),('RUB','KRW','29.7282','1018.755'),('PLN','RUB','11.2963','34.272'),('HKD','NOK','0.7884','6.1107'),('ILS','PHP','12.7357','43.84'),('CNY','ILS','0.5524','3.4423'),('TRY','LVL','0.2394','0.5095'),('JPY','CZK','0.1978','20.142'),('NZD','HUF','195.4596','224.135'),('LTL','JPY','40.1732','101.845'),('KRW','CAD','0.0011','1.0826'),('SGD','KRW','816.2676','1018.755'),('PHP','BRL','0.0507','2.223'),('RUB','MYR','0.0938','3.213'),('INR','GBP','0.0098','0.5871'),('TRY','BRL','1.0444','2.223'),('HUF','PLN','0.0135','3.0338'),('AUD','DKK','5.1518','5.4744'),('MXN','ILS','0.2652','3.4423'),('RON','KRW','315.8196','1018.755'),('MXN','RON','0.2485','3.2253'),('ILS','GBP','0.1706','0.5871'),('BGN','RON','2.2373','3.2253'),('IDR','ZAR','9.0E-4','10.6466'),('TRY','HUF','105.2854','224.135'),('HRK','BGN','0.2592','1.4417'),('GBP','BGN','2.4555','1.4417'),('USD','ZAR','10.6466','10.6466'),('HRK','IDR','2151.7942','11970.0'),('USD','MXN','12.982','12.982'),('NZD','LTL','2.211','2.5352'),('CNY','BGN','0.2314','1.4417'),('GBP','AUD','1.8098','1.0626'),('NZD','CNY','5.4343','6.231'),('IDR','DKK','5.0E-4','5.4744'),('HUF','JPY','0.4544','101.845'),('KRW','MXN','0.0127','12.982'),('RUB','MXN','0.3788','12.982'),('BGN','NOK','4.2383','6.1107'),('MYR','HRK','1.7313','5.5628'),('LVL','BGN','2.8296','1.4417'),('SGD','TRY','1.7054','2.1285'),('MXN','PHP','3.3769','43.84'),('HUF','RUB','0.1529','34.272'),('GBP','THB','55.3027','32.47'),('PHP','RON','0.0736','3.2253'),('ZAR','PHP','4.1181','43.84'),('NOK','ZAR','1.7422','10.6466'),('TRY','LTL','1.1911','2.5352'),('SEK','LVL','0.0764','0.5095'),('RUB','PHP','1.2793','43.84'),('SEK','JPY','15.2663','101.845'),('HKD','BRL','0.2868','2.223'),('PHP','DKK','0.1249','5.4744'),('MYR','HUF','69.7526','224.135'),('NZD','EUR','0.6403','0.7342'),('TRY','HRK','2.6137','5.5628'),('USD','THB','32.47','32.47'),('NZD','AUD','0.9267','1.0626'),('KRW','MYR','0.0032','3.213'),('HKD','INR','7.7456','60.035'),('SGD','BRL','1.7812','2.223'),('NOK','USD','0.1637','1.0'),('LTL','BRL','0.8769','2.223'),('INR','CAD','0.018','1.0826'),('MXN','INR','4.6244','60.035'),('JPY','BGN','0.0142','1.4417'),('BRL','ZAR','4.7891','10.6466'),('DKK','ZAR','1.9447','10.6466'),('SGD','DKK','4.3861','5.4744'),('DKK','MXN','2.3715','12.982'),('NOK','SGD','0.2043','1.2481'),('CZK','THB','1.6121','32.47'),('CAD','DKK','5.0569','5.4744'),('HKD','TRY','0.2746','2.1285'),('PLN','HRK','1.8337','5.5628'),('PHP','NOK','0.1394','6.1107'),('CAD','ZAR','9.8333','10.6466'),('NZD','HRK','4.8519','5.5628'),('LVL','ZAR','20.8939','10.6466'),('SEK','CNY','0.934','6.231'),('RUB','BRL','0.0649','2.223'),('AUD','THB','30.5578','32.47'),('SGD','RUB','27.4577','34.272'),('HUF','GBP','0.0026','0.5871'),('IDR','HKD','6.0E-4','7.7508'),('LTL','TRY','0.8396','2.1285'),('PHP','JPY','2.3231','101.845'),('THB','DKK','0.1686','5.4744'),('HKD','PLN','0.3914','3.0338'),('KRW','RUB','0.0336','34.272'),('IDR','BGN','1.0E-4','1.4417'),('PHP','NZD','0.0262','1.1466'),('HUF','LTL','0.0113','2.5352'),('LTL','PLN','1.1966','3.0338'),('BRL','THB','14.6064','32.47'),('CNY','PLN','0.4869','3.0338'),('GBP','HRK','9.4752','5.5628'),('PHP','TRY','0.0486','2.1285'),('SGD','ZAR','8.5296','10.6466'),('LTL','BGN','0.5687','1.4417'),('KRW','PLN','0.003','3.0338'),('SEK','HRK','0.8338','5.5628'),('CZK','IDR','594.2806','11970.0'),('PLN','HKD','2.5549','7.7508'),('DKK','KRW','186.1012','1018.755'),('DKK','MYR','0.5869','3.213'),('HRK','DKK','0.9841','5.4744'),('HKD','RUB','4.4213','34.272'),('EUR','AUD','1.4473','1.0626'),('CNY','MXN','2.0835','12.982'),('RUB','PLN','0.0885','3.0338'),('LVL','USD','1.9627','1.0'),('BRL','PHP','19.7211','43.84'),('USD','BGN','1.4417','1.4417'),('RON','AUD','0.3294','1.0626'),('NOK','CHF','0.1462','0.8933'),('PLN','DKK','1.8045','5.4744'),('NZD','JPY','88.8231','101.845'),('MXN','RUB','2.6399','34.272'),('EUR','KRW','1387.6105','1018.755'),('NOK','NZD','0.1876','1.1466'),('LVL','HRK','10.9193','5.5628'),('BGN','PHP','30.4085','43.84'),('DKK','ILS','0.6288','3.4423'),('NZD','LVL','0.4444','0.5095'),('ILS','MXN','3.7713','12.982'),('SGD','IDR','9590.8467','11970.0'),('ZAR','MXN','1.2196','12.982'),('IDR','RON','3.0E-4','3.2253'),('HRK','THB','5.837','32.47'),('CHF','JPY','114.0181','101.845'),('TRY','RON','1.5154','3.2253'),('BGN','CAD','0.7509','1.0826'),('DKK','USD','0.1827','1.0'),('NZD','CZK','17.5675','20.142'),('USD','DKK','5.4744','5.4744'),('MXN','TRY','0.164','2.1285'),('HRK','INR','10.7922','60.035'),('PHP','LTL','0.0578','2.5352'),('SEK','CZK','3.0194','20.142'),('HRK','RON','0.5798','3.2253'),('USD','MYR','3.213','3.213'),('CAD','PHP','40.497','43.84'),('SEK','LTL','0.38','2.5352'),('ILS','IDR','3477.3262','11970.0'),('HRK','PHP','7.8809','43.84'),('SGD','BGN','1.1551','1.4417'),('KRW','BRL','0.0022','2.223'),('MXN','KRW','78.4729','1018.755'),('SEK','USD','0.1499','1.0'),('CNY','IDR','1921.0399','11970.0'),('INR','SEK','0.1111','6.6709'),('ZAR','MYR','0.3018','3.213'),('JPY','DKK','0.0538','5.4744'),('PHP','BGN','0.0329','1.4417'),('AUD','MYR','3.0238','3.213'),('JPY','THB','0.3188','32.47'),('LTL','RON','1.2723','3.2253'),('CAD','THB','29.994','32.47'),('KRW','GBP','6.0E-4','0.5871'),('HUF','HRK','0.0248','5.5628'),('ZAR','AUD','0.0998','1.0626'),('GBP','HUF','381.7115','224.135'),('AUD','MXN','12.2173','12.982'),('BGN','IDR','8302.6982','11970.0'),('ZAR','CZK','1.8921','20.142'),('LTL','DKK','2.1593','5.4744'),('CNY','PHP','7.0358','43.84'),('CNY','KRW','163.4978','1018.755'),('HKD','PHP','5.6562','43.84'),('DKK','INR','10.9669','60.035'),('TRY','RUB','16.1015','34.272'),('PHP','LVL','0.0116','0.5095'),('ILS','TRY','0.6183','2.1285'),('EUR','ILS','4.6886','3.4423'),('HRK','ILS','0.6188','3.4423'),('PLN','NOK','2.0142','6.1107'),('KRW','PHP','0.043','43.84'),('LTL','PHP','17.2929','43.84'),('THB','BGN','0.0444','1.4417'),('LVL','AUD','2.0855','1.0626'),('SEK','AUD','0.1593','1.0626'),('THB','NOK','0.1882','6.1107'),('PLN','BGN','0.4752','1.4417'),('PLN','RON','1.0632','3.2253'),('INR','SGD','0.0208','1.2481'),('MYR','DKK','1.7038','5.4744'),('ILS','MYR','0.9334','3.213'),('HUF','NZD','0.0051','1.1466'),('CNY','THB','5.211','32.47'),('LTL','THB','12.8079','32.47'),('AUD','CZK','18.9568','20.142'),('TRY','PLN','1.4253','3.0338'),('IDR','LTL','2.0E-4','2.5352'),('CNY','GBP','0.0942','0.5871'),('CNY','BRL','0.3568','2.223'),('RUB','INR','1.7519','60.035'),('NOK','LVL','0.0834','0.5095'),('IDR','TRY','2.0E-4','2.1285'),('HUF','LVL','0.0023','0.5095'),('BGN','PLN','2.1043','3.0338'),('CHF','CZK','22.5495','20.142'),('SGD','MXN','10.4025','12.982'),('HRK','KRW','183.1371','1018.755'),('ZAR','HKD','0.7281','7.7508'),('HUF','TRY','0.0095','2.1285'),('PLN','THB','10.7031','32.47'),('EUR','CZK','27.4361','20.142'),('EUR','INR','81.7716','60.035'),('BGN','GBP','0.4072','0.5871'),('NZD','HKD','6.7598','7.7508'),('NOK','EUR','0.1202','0.7342'),('HRK','BRL','0.3996','2.223'),('RUB','TRY','0.0621','2.1285'),('LVL','HUF','439.8822','224.135'),('PLN','PHP','14.451','43.84'),('AUD','HUF','210.9169','224.135'),('SEK','EUR','0.1101','0.7342'),('CHF','HKD','8.6772','7.7508'),('LTL','HKD','3.0573','7.7508'),('SGD','MYR','2.5744','3.213'),('HRK','PLN','0.5453','3.0338'),('INR','CHF','0.0149','0.8933'),('DKK','CNY','1.1382','6.231'),('TRY','HKD','3.6414','7.7508'),('CZK','BGN','0.0716','1.4417'),('RON','CZK','6.2437','20.142'),('JPY','IDR','117.5315','11970.0'),('BGN','RUB','23.7702','34.272'),('BRL','GBP','0.2641','0.5871'),('CNY','RON','0.5177','3.2253'),('KRW','CNY','0.0061','6.231'),('THB','RUB','1.0555','34.272'),('LVL','NZD','2.2506','1.1466'),('CZK','RON','0.1602','3.2253'),('GBP','BRL','3.7862','2.223'),('TRY','PHP','20.5967','43.84'),('RUB','BGN','0.0421','1.4417'),('SGD','PHP','35.1264','43.84'),('NOK','KRW','166.7261','1018.755'),('PLN','KRW','335.8127','1018.755'),('DKK','PLN','0.5542','3.0338'),('LTL','HUF','88.4129','224.135'),('THB','ZAR','0.3279','10.6466'),('RON','ZAR','3.3001','10.6466'),('MYR','BGN','0.4487','1.4417'),('INR','CNY','0.1038','6.231'),('BGN','SEK','4.6268','6.6709'),('PLN','IDR','3945.677','11970.0'),('TRY','GBP','0.2758','0.5871'),('CZK','GBP','0.0291','0.5871'),('RUB','NOK','0.1783','6.1107'),('PHP','SEK','0.1522','6.6709'),('CZK','HKD','0.3848','7.7508'),('TRY','THB','15.2549','32.47'),('CNY','RUB','5.5002','34.272'),('INR','LTL','0.0422','2.5352'),('BRL','ILS','1.5485','3.4423'),('JPY','CNY','0.0612','6.231'),('HUF','DKK','0.0244','5.4744'),('INR','HUF','3.7328','224.135'),('KRW','ILS','0.0034','3.4423'),('JPY','MXN','0.1275','12.982'),('INR','HRK','0.0927','5.5628'),('CAD','AUD','0.9815','1.0626'),('CZK','JPY','5.0563','101.845'),('PHP','GBP','0.0134','0.5871'),('PHP','CAD','0.0247','1.0826'),('AUD','KRW','958.7605','1018.755'),('PLN','TRY','0.7016','2.1285'),('MXN','DKK','0.4217','5.4744'),('CHF','CNY','6.9758','6.231'),('MYR','THB','10.1058','32.47'),('USD','BRL','2.223','2.223'),('THB','KRW','31.3753','1018.755'),('USD','PLN','3.0338','3.0338'),('USD','RUB','34.272','34.272'),('JPY','MYR','0.0315','3.213'),('RUB','ZAR','0.3106','10.6466'),('MYR','PHP','13.6446','43.84'),('CHF','KRW','1140.5229','1018.755'),('ILS','INR','17.4404','60.035'),('BRL','RON','1.4509','3.2253'),('AUD','GBP','0.5526','0.5871'),('ILS','AUD','0.3087','1.0626'),('SGD','THB','26.0163','32.47'),('THB','TRY','0.0656','2.1285'),('BRL','INR','27.0063','60.035'),('NZD','CAD','0.9442','1.0826'),('ILS','USD','0.2905','1.0'),('BGN','INR','41.6418','60.035'),('CZK','BRL','0.1104','2.223'),('CZK','PLN','0.1506','3.0338'),('CHF','USD','1.1195','1.0'),('SEK','CAD','0.1623','1.0826'),('HRK','HUF','40.2927','224.135'),('KRW','INR','0.0589','60.035'),('CHF','EUR','0.8219','0.7342'),('RON','SEK','2.0681','6.6709'),('SEK','HUF','33.5942','224.135'),('LVL','SGD','2.4496','1.2481'),('ILS','KRW','295.9518','1018.755'),('BRL','PLN','1.3646','3.0338'),('NOK','INR','9.8251','60.035'),('BRL','BGN','0.6485','1.4417'),('SGD','CZK','16.1398','20.142'),('DKK','PHP','8.0085','43.84'),('RUB','DKK','0.1597','5.4744'),('AUD','ILS','3.2396','3.4423'),('INR','JPY','1.6964','101.845'),('CAD','HKD','7.1598','7.7508'),('EUR','THB','44.2262','32.47'),('IDR','CZK','0.0017','20.142'),('DKK','SEK','1.2187','6.6709'),('ZAR','HUF','21.0521','224.135'),('BRL','RUB','15.4157','34.272'),('AUD','INR','56.4995','60.035'),('CAD','CZK','18.6061','20.142'),('CHF','MXN','14.5335','12.982'),('DKK','CHF','0.1632','0.8933'),('EUR','IDR','16303.918','11970.0'),('BGN','ILS','2.3877','3.4423'),('MXN','THB','2.5011','32.47'),('LTL','HRK','2.1943','5.5628'),('RUB','THB','0.9475','32.47'),('NZD','SGD','1.0885','1.2481'),('ZAR','THB','3.0502','32.47'),('NOK','ILS','0.5634','3.4423'),('CZK','PHP','2.1765','43.84'),('USD','PHP','43.84','43.84'),('CHF','AUD','1.1896','1.0626'),('PLN','MXN','4.2792','12.982'),('HRK','RUB','6.1604','34.272'),('MXN','BGN','0.1111','1.4417'),('JPY','EUR','0.0072','0.7342'),('JPY','AUD','0.0104','1.0626'),('ZAR','HRK','0.5226','5.5628'),('THB','BRL','0.0685','2.223'),('IDR','NZD','1.0E-4','1.1466'),('NZD','IDR','10439.5146','11970.0'),('MXN','NOK','0.4707','6.1107'),('PLN','BRL','0.7328','2.223'),('MYR','PLN','0.9442','3.0338'),('MYR','ZAR','3.3135','10.6466'),('ZAR','IDR','1124.4663','11970.0'),('PLN','GBP','0.1935','0.5871'),('JPY','ILS','0.0338','3.4423'),('INR','USD','0.0167','1.0'),('THB','MXN','0.3998','12.982'),('DKK','SGD','0.228','1.2481'),('GBP','LVL','0.8678','0.5095'),('NZD','SEK','5.8177','6.6709'),('RON','CAD','0.3356','1.0826'),('TRY','IDR','5623.6787','11970.0'),('NOK','CNY','1.0197','6.231'),('EUR','MYR','4.3763','3.213'),('CNY','HUF','35.9685','224.135'),('LVL','JPY','199.892','101.845'),('THB','MYR','0.099','3.213'),('SEK','CHF','0.1339','0.8933'),('IDR','AUD','1.0E-4','1.0626'),('BGN','MYR','2.2286','3.213'),('LVL','IDR','23493.6191','11970.0'),('ZAR','TRY','0.2','2.1285'),('KRW','SGD','0.0012','1.2481'),('AUD','CNY','5.8641','6.231'),('HUF','THB','0.1449','32.47'),('KRW','EUR','7.0E-4','0.7342'),('GBP','IDR','20387.2441','11970.0'),('CAD','LVL','0.4706','0.5095'),('TRY','BGN','0.6773','1.4417'),('THB','PLN','0.0934','3.0338'),('LTL','AUD','0.4191','1.0626'),('USD','KRW','1018.755','1018.755'),('CZK','HRK','0.2762','5.5628'),('CAD','USD','0.9237','1.0'),('SEK','IDR','1794.2665','11970.0'),('GBP','LTL','4.3179','2.5352'),('RON','EUR','0.2276','0.7342'),('HKD','BGN','0.186','1.4417'),('HKD','EUR','0.0947','0.7342'),('HUF','PHP','0.1956','43.84'),('JPY','INR','0.5895','60.035'),('PLN','MYR','1.0591','3.213'),('CZK','NZD','0.0569','1.1466'),('ZAR','KRW','95.6959','1018.755'),('BRL','DKK','2.4625','5.4744'),('USD','ILS','3.4423','3.4423'),('NZD','CHF','0.779','0.8933'),('ZAR','BGN','0.1354','1.4417'),('LVL','SEK','13.0935','6.6709'),('GBP','NZD','1.9529','1.1466'),('CZK','RUB','1.7015','34.272'),('LVL','BRL','4.3631','2.223'),('NOK','CZK','3.2964','20.142'),('RON','CNY','1.9316','6.231'),('EUR','GBP','0.7997','0.5871'),('HUF','IDR','53.4041','11970.0'),('LVL','GBP','1.1524','0.5871'),('KRW','IDR','11.7496','11970.0'),('BGN','NZD','0.7953','1.1466'),('SGD','AUD','0.8514','1.0626'),('EUR','MXN','17.6823','12.982'),('MYR','RON','1.0038','3.2253'),('BGN','MXN','9.0046','12.982'),('RON','SGD','0.3869','1.2481'),('RON','LVL','0.1579','0.5095'),('EUR','BGN','1.9637','1.4417'),('INR','AUD','0.0177','1.0626'),('INR','HKD','0.1291','7.7508'),('GBP','TRY','3.6253','2.1285'),('DKK','CAD','0.1978','1.0826'),('CAD','JPY','94.0788','101.845'),('MYR','JPY','31.6978','101.845'),('IDR','HUF','0.0187','224.135'),('SGD','PLN','2.4306','3.0338'),('USD','INR','60.035','60.035'),('LVL','LTL','4.9758','2.5352'),('AUD','IDR','11265.0859','11970.0'),('HKD','THB','4.1892','32.47'),('RON','CHF','0.2769','0.8933'),('TRY','DKK','2.5718','5.4744'),('MYR','MXN','4.0404','12.982'),('MYR','TRY','0.6625','2.1285'),('BRL','MXN','5.8398','12.982'),('BGN','BRL','1.5419','2.223'),('HUF','BGN','0.0064','1.4417'),('CNY','CAD','0.1737','1.0826'),('THB','INR','1.8489','60.035'),('KRW','USD','0.001','1.0'),('THB','PHP','1.3502','43.84'),('INR','CZK','0.3355','20.142'),('BRL','MYR','1.4453','3.213'),('CHF','SEK','7.4677','6.6709'),('HRK','GBP','0.1055','0.5871'),('HRK','CAD','0.1946','1.0826'),('RON','LTL','0.7859','2.5352'),('RON','USD','0.31','1.0'),('CZK','LVL','0.0253','0.5095'),('GBP','JPY','173.4619','101.845'),('CAD','HRK','5.1392','5.5628'),('THB','ILS','0.106','3.4423'),('ZAR','INR','5.6397','60.035'),('USD','TRY','2.1285','2.1285'),('CZK','TRY','0.1057','2.1285'),('LTL','CZK','7.9449','20.142'),('NOK','AUD','0.1739','1.0626'),('DKK','NOK','1.1162','6.1107'),('CNY','HRK','0.8929','5.5628'),('JPY','KRW','10.003','1018.755'),('MYR','HKD','2.4123','7.7508'),('BRL','KRW','458.2794','1018.755'),('HKD','MYR','0.4145','3.213'),('BGN','KRW','706.6345','1018.755'),('CAD','HUF','207.0435','224.135'),('KRW','SEK','0.0065','6.6709'),('USD','RON','3.2253','3.2253'),('KRW','CHF','9.0E-4','0.8933'),('ZAR','DKK','0.5143','5.4744'),('PHP','RUB','0.7817','34.272'),('CAD','LTL','2.3418','2.5352'),('JPY','USD','0.0098','1.0'),('HKD','MXN','1.675','12.982'),('BRL','TRY','0.9575','2.1285'),('ZAR','ILS','0.3234','3.4423'),('INR','LVL','0.0085','0.5095'),('BGN','SGD','0.8657','1.2481'),('ZAR','RON','0.303','3.2253'),('RON','NZD','0.3555','1.1466'),('THB','RON','0.0993','3.2253'),('IDR','HRK','5.0E-4','5.5628'),('CHF','SGD','1.3972','1.2481'),('USD','NOK','6.1107','6.1107'),('MYR','CZK','6.2692','20.142'),('CZK','HUF','11.1277','224.135'),('EUR','DKK','7.4559','5.4744'),('SEK','SGD','0.1871','1.2481'),('CZK','LTL','0.1259','2.5352'),('CHF','ZAR','11.9176','10.6466'),";
        if (null != this.conn && null != stmt && !Strings.isNullOrEmpty(sql_insert_values)) {
            result = sqlExecutor(sql_insert_values);
        }else {
            logger.error("Query Table Error.");
        }
        return result;
    }
    /*
     * FROMTO - DOUBLE_RATE
     * ------ - -----------
     * THBRON - 0.0996
     * IDRHRK - 5.0E-4
     * CHFSGD - 1.3964
     * (non-Javadoc)
     * @see com.ebj.dao.DBBaseDaoI#doInsert()
     */
    @Override
    public boolean doInsert() {
        boolean result = false;
        
        String sql_kit_values_str = buildInsertSQLHeader() + getSQLValues();
        if (null != this.conn && null != stmt && !Strings.isNullOrEmpty(sql_kit_values_str)) {
            Stopwatch stopwatch = Stopwatch.createStarted();
            result = sqlExecutor(sql_kit_values_str);
            if (logger.isDebugEnabled()) {
                logger.debug("SQL_KIT_VALUES_STR :\r\n[" + sql_kit_values_str + "].");
                logger.debug("Insert Datas Cost [" + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "] MilliSeconds.");
            }
        }else {
            logger.error("Query Table Error.");
        }
        
        return result;
    }
    
    @Override
    public boolean doDelete() {
        return false;
    }
    
    @Override
    public boolean doUpdate() {
        return false;
    }
    
    @Override
    public ResultSet doQuery(String sql) {
        return queryExecutor(sql);
    }
    
    public ResultSet doQuery(String colums, String tableName) {
    	String sql = config.getSQLTmplQuery(colums, tableName);
    	return queryExecutor(sql);
    }

    public String getTableName() {
        return tableName;
    }
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public Object[] getParams() {
        return params;
    }
    public void setParams(Object[] params) {
        this.params = params;
    }

    
    public Map<String, Double> getValue_map() {
        return value_map;
    }
    public void setValue_map(Map<String, Double> value_map) {
        this.value_map = value_map;
    }

    public H2DBService getH2dbService() {
        return h2dbService;
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        
        H2DBDao h2dbDao = H2DBDao.getInstance();
        boolean res = h2dbDao.createTable("YAHOO_XCHANGE_RATE");
        String sql = "SELECT * FROM YAHOO_XCHANGE_RATE";
        boolean duIstOrUpdt = h2dbDao.doInsertOrUpdate();
        
        if (duIstOrUpdt) {
            ResultSet resultSet = h2dbDao.queryExecutor(sql);
            
            try {
                String[] params = {"ID","CURRENCY_FROM","CURRENCY_TO","RATE_FROM_TO","RATE_USD_TO","IS_DELETED","LAST_UPDATE_TIME"};
                while (resultSet.next()) {
                    String str = "";
                    
                    for (int i = 0; i < params.length; i++) {
                        str += resultSet.getObject(params[i].toString());
                        if (i != params.length - 1 ) {
                            str += ",";
                        }
                        
                    }
                    list.add(str);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }finally{
                // ...
            }
        }
//        String sql2 = "CREATE TABLE currency_exchanger(id int(32) unsigned NOT NULL AUTO_INCREMENT,rrate decimal(10,4) NOT NULL,crate decimal(10,4) NOT NULL,lcurrency varchar(3) NOT NULL,rcurrency varchar(3) NOT NULL,isDeleted tinyint(1) DEFAULT '0',last_update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (id),UNIQUE KEY currency_exchanger_lcurrency_IDX (lcurrency,rcurrency),KEY lcurrency (lcurrency) USING HASH,KEY rcurrency (rcurrency) USING HASH)";
        String sql_drop_table = "DROP TABLE IF EXISTS YAHOO_XCHANGE_RATE";
//        String sql2 = "CREATE TABLE YAHOO_XCHANGE_RATE(ID INT PRIMARY KEY,RRATE DECIMAL NOT NULL,CRATE DECIMAL NOT NULL,LCURRENCY VARCHAR(3) NOT NULL,RCURRENCY VARCHAR(3) NOT NULL,IS_DELETED TINYINT DEFAULT 0,LAST_UPDATE_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
        String sql_create_table = "CREATE TABLE YAHOO_XCHANGE_RATE ("
                + "ID INT PRIMARY KEY AUTO_INCREMENT NOT NULL,"
                + "CURRENCY_FROM VARCHAR(3) NOT NULL,"
                + "CURRENCY_TO VARCHAR(3) NOT NULL,"
                + "RATE_FROM_TO DECIMAL(10,4) NOT NULL,"
                + "RATE_USD_TO DECIMAL(10,4) NOT NULL,"
                + "IS_DELETED TINYINT DEFAULT 0,"
                + "LAST_UPDATE_TIME TIMESTAMP AS CURRENT_TIMESTAMP(),"
                + "PRIMARY KEY (ID),"
                + "UNIQUE (CURRENCY_FROM, CURRENCY_TO)"
                + ");";
        String sql_insert_datas = "INSERT INTO YAHOO_XCHANGE_RATE "
                + "(CURRENCY_FROM, CURRENCY_TO, RATE_FROM_TO, RATE_USD_TO) "
                + "VALUES "
                + "('DDY','DIY','0.3399','1.12389'),"
                + "('DDK','DJY','0.5566','2.12389') ";
        
//        boolean step_a = h2dbDao.sqlExecutor(sql_drop_table);
//        boolean step_b = h2dbDao.sqlExecutor(sql_create_table);
//        boolean step_c = h2dbDao.sqlExecutor(sql_insert_datas);
//        System.out.println("drop : " + step_a);
//        System.out.println("create : " + step_b);
//        System.out.println("insert datas : " + step_c);
        
        for (String string : list) {
            System.out.println(string);
        }
    }
}
